"""
1.已知列表names = ['old_driver','rain','jack','shanshan','peiqi','black_girl']

 a.取出names列表中索引4-7的元素

 b.取出names列表中索引2-10的元素，步长为2

 c.取出names列表中最后3个元素

 d.循环names列表，打印每个元素的索引值，和元素，当索引值 为偶数时，把对应的元素改成-1


"""


names = ['old_driver','rain','jack','shanshan','peiqi','black_girl']

# a.取出names列表中索引4-7的元素
print(names[4:7])

# b.取出names列表中索引2-10的元素，步长为2
print(names[2:10:2])

#  c.取出names列表中最后3个元素
print(names[-3:])

# d.循环names列表，打印每个元素的索引值，和元素，当索引值 为偶数时，把对应的元素改成-1
for i,name in enumerate(names):
    if i % 2 == 0 and i != 0:
        names[i] = -1

print(names)


# 2.已知一个列表names2 = ['鲁班七号','后裔', '狄仁杰', '黄忠', '孙尚香']，编写程序用两种方法获取names中的元素黄忠
names2 = ['鲁班七号','后裔', '狄仁杰', '黄忠', '孙尚香']

for i,name in enumerate(names2):
    if names2[i]  == '黄忠' :
        print(i, name)

for i1 in range(0,len(names2)):
    if names2[i1]  == '黄忠' :
        print(i1, names2[i1])

# 已知一个数字列表nums = [1, 2, 3,1, 4, 2, 1 ,3, 7, 3, 3]，输出索引为奇数的元素
nums = [1, 2, 3,1, 4, 2, 1 ,3, 7, 3, 3]
for i,num in enumerate(nums):
    if i % 2  != 0 and i != 1 :
        print(i, num)
